package com.ruoyi.lqm.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lqm.domain.LqmCategorys;
import com.ruoyi.lqm.service.ILqmCategorysService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 商品分类Controller
 * 
 * @author dell
 * @date 2019-09-30
 */
@Controller
@RequestMapping("/lqm/categorys")
public class LqmCategorysController extends BaseController
{
    private String prefix = "lqm/categorys";

    @Autowired
    private ILqmCategorysService lqmCategorysService;

    @RequiresPermissions("lqm:categorys:view")
    @GetMapping()
    public String categorys()
    {
        return prefix + "/categorys";
    }

    /**
     * 查询商品分类列表
     */
    @RequiresPermissions("lqm:categorys:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LqmCategorys lqmCategorys)
    {
        startPage();
        List<LqmCategorys> list = lqmCategorysService.selectLqmCategorysList(lqmCategorys);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @RequiresPermissions("lqm:categorys:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LqmCategorys lqmCategorys)
    {
        List<LqmCategorys> list = lqmCategorysService.selectLqmCategorysList(lqmCategorys);
        ExcelUtil<LqmCategorys> util = new ExcelUtil<LqmCategorys>(LqmCategorys.class);
        return util.exportExcel(list, "categorys");
    }

    /**
     * 新增商品分类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品分类
     */
    @RequiresPermissions("lqm:categorys:add")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LqmCategorys lqmCategorys)
    {
        return toAjax(lqmCategorysService.insertLqmCategorys(lqmCategorys));
    }

    /**
     * 修改商品分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        LqmCategorys lqmCategorys = lqmCategorysService.selectLqmCategorysById(id);
        mmap.put("lqmCategorys", lqmCategorys);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品分类
     */
    @RequiresPermissions("lqm:categorys:edit")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LqmCategorys lqmCategorys)
    {
        return toAjax(lqmCategorysService.updateLqmCategorys(lqmCategorys));
    }

    /**
     * 删除商品分类
     */
    @RequiresPermissions("lqm:categorys:remove")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lqmCategorysService.deleteLqmCategorysByIds(ids));
    }
}
